home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DBVGAL17.ARJ / SRC_C.ARJ / VESA8.C < prev    next >
C/C++ Source or Header  |  1992-01-26  |  8KB  |  224 lines

  1. #define VESA8
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <alloc.h>
  6. #include <mem.h>
  7. #include <dos.h>
  8. #include "vidlib.h"
  9. #include "vesa.h"
  10.  
  11. int VESAfill256(unsigned dx, unsigned dy, unsigned sdx, unsigned sdy,
  12.                 unsigned color)
  13. {
  14.    char *dest;
  15.    int  tempdx;
  16.  
  17.    VESAsetpage(VESAwhat_page(dy, dx));
  18.    dest=(char *)normalize(_screen_start + VESAwhat_offset(dy,dx));
  19.    if (vgadebug) {
  20.        fprintf(vgadebug,"\nVESAfill256(dx=%u, %u, sdx=%u, sdy=%u, color=%u)\n",
  21.                         dx,dy,sdx,sdy,color);
  22.        fflush(vgadebug);
  23.    }
  24.    while (sdy>0) {
  25.        while ((Vnext_break_row != dy) && (sdy>0)){
  26.           setmem(dest, sdx, color);
  27.           dy++; sdy--;
  28.           dest=(char *)normalize(dest+_screen_width);
  29.        }
  30.        if ((sdy>0) && (Vnext_break_row == dy)) {
  31.      tempdx=Vnext_break_col - dx; /* number of bytes */
  32.      if ( tempdx < 1 ) { /* no bytes to output on this page */
  33.         VESAsetpage(vesapage+1);
  34.         dest=(char *)normalize (_screen_start + VESAwhat_offset(dy,dx) );
  35.             setmem(dest, sdx, color);
  36.             dy++; sdy--;
  37.             continue;
  38.          }
  39.          if ( sdx > tempdx ) {    /* split page */
  40.             setmem(dest, tempdx, color);
  41.             VESAsetpage(vesapage+1);
  42.             dest=(char *)normalize
  43.             (_screen_start + VESAwhat_offset(dy,dx+tempdx) );
  44.             setmem(dest, (sdx-tempdx), color);
  45.      } else { /* then all on this page */
  46.         setmem(dest, sdx, color);
  47.         VESAsetpage(vesapage+1);
  48.      }
  49.      dy++; sdy--;
  50.      dest=(char *)normalize(_screen_start + VESAwhat_offset(dy,dx));
  51.        }
  52.    }
  53.    return(1);
  54.  
  55. }
  56.  
  57. /* Currently, we assume the worst and perform all copies through system */
  58. /* memory.                                */
  59. int VESAcopy256(unsigned dx, unsigned dy,
  60.              unsigned sx, unsigned sy,
  61.              unsigned sdx, unsigned sdy)
  62. {
  63.    char *temp;
  64.    int i,g, b, direction;
  65.    long t;
  66.  
  67.    /* determine if the source is less than the destination, and overlaps */
  68.    if ( (sy < dy) && (sy+sdy > dy) && (sx+sdx > dx) && (dx+sdx > sx) )
  69.         direction=-1;
  70.    else
  71.         direction=1;
  72.    t=(long)sdx*sdy;
  73.    if (t < 16385) {
  74.       g=sdy;
  75.    } else {
  76.       g=16384/sdx;
  77.       t=g*sdx;
  78.    }
  79.    if ( (temp=(char *)malloc((unsigned)t)) == NULL) {
  80.       return(0);
  81.    }
  82.    if (vgadebug) {
  83.       fprintf(vgadebug,
  84.               "\nVESAcopy256(dx=%u, dy=%u,  sx=%u, sy=%u,  sdx=%u, sdy=%u)\n",
  85.                            dx,dy,sx,sy,sdx,sdy);
  86.       fprintf(vgadebug,"   temp=%Fp, _s_s=%Fp, _s_w=%u, g=%u, direction=%i"
  87.                        ", core=%lu\n",
  88.               temp, _screen_start, _screen_width, g, direction,coreleft());
  89.       fflush(vgadebug);
  90.    }
  91.    if ( direction > 0 ) {
  92.       for (i=sy; i<sy+sdy; i+=g, dy+=g) {
  93.          b=(( (sy+sdy-i) < g ) ? (sy+sdy-i) : g );
  94.          VESAcapt256(temp, sdx, g, 0, 0, sx, i, sdx, b, 1);
  95.          VESAdisp256(dx, dy, temp, sdx, g, 0, 0, sdx, b, 1);
  96.       }
  97.    } else {
  98.       i=(sy+sdy); b=g; dy+=sdy;
  99.       while ( i > sy ) {
  100.          if ( sy+b > i ) {
  101.             b=i-sy; i=sy; dy-=b;
  102.          } else {
  103.             i-=g; dy-=g;
  104.          }
  105.          VESAcapt256(temp, sdx, g, 0, 0, sx, i, sdx, b, -1);
  106.          VESAdisp256(dx, dy, temp, sdx, g, 0, 0, sdx, b, -1);
  107.       }
  108.    }
  109.    free(temp);
  110.    return(1);
  111. }
  112.  
  113. /* System memory to video copy */
  114. int VESAdisp256(unsigned dx, unsigned dy,
  115.          char *s, unsigned sw, unsigned sl,
  116.              unsigned sx, unsigned sy,
  117.              unsigned sdx, unsigned sdy, int direction)
  118. {
  119.    char *src;
  120.    char *dest;
  121.    int  tempdx;
  122.  
  123.    src=(char *)normalize(s + sy*sw + sx);
  124.    VESAsetpage(VESAwhat_page(dy, dx));
  125.    dest=(char *)normalize(_screen_start + VESAwhat_offset(dy,dx));
  126.    if (vgadebug) {
  127.        fprintf(vgadebug,"\nVESAdisp256(dx=%u, %u, s=%Fp,"
  128.                         " sw=%u, %u, sx=%u, %u,  sdx=%u, sdy=%u, "
  129.                         "direction=%u)\n",
  130.                         dx,dy,s,sw,sl,sx,sy,sdx,sdy,direction);
  131.        fflush(vgadebug);
  132.    }
  133.    while (sdy>0) {
  134.        while ((Vnext_break_row != dy) && (sdy>0)){
  135.       /* while we're not on a break row and we've still got work ... */
  136.       memcpy(dest, src, sdx);
  137.       dy++; sdy--;
  138.       dest=dest+_screen_width; /* don't need to normalize dest */
  139.       src=(char *)normalize(src+sw);
  140.        }
  141.        if ((sdy>0) && (Vnext_break_row == dy)) {
  142.      /* if we've still got lines to do and we're on a break row ... */
  143.      /* Vnext_break_col is the first byte in the next page */
  144.      tempdx=Vnext_break_col - dx; /* number of bytes on this page */
  145.      if ( tempdx < 1 ) { /* no bytes to output on this page */
  146.         VESAsetpage(vesapage+1);
  147.         dest=(char *)normalize (_screen_start + VESAwhat_offset(dy,dx) );
  148.             memcpy(dest, src, sdx);
  149.             dy++; sdy--;
  150.             if (sdy) src=(char *)normalize(src + sw);
  151.             continue;
  152.          }
  153.          if ( sdx > tempdx ) {    /* split page */
  154.             memcpy(dest, src, tempdx);
  155.             VESAsetpage(vesapage+1);
  156.             dest=(char *)normalize
  157.             (_screen_start + VESAwhat_offset(dy,dx+tempdx) );
  158.             memcpy(dest, src+tempdx, (sdx-tempdx));
  159.          } else { /* then sdx <= tempdx */
  160.             memcpy(dest, src, sdx);
  161.             VESAsetpage(vesapage+1);
  162.          }
  163.          dy++; sdy--;
  164.      dest=(char *)normalize(_screen_start + VESAwhat_offset(dy,dx));
  165.        }
  166.        if (sdy) src=(char *)normalize(src + sw);
  167.    }
  168.    return(1);
  169. }
  170. /* Video to System memory copy */
  171. int VESAcapt256(char *d, unsigned dw, unsigned dl,
  172.                       unsigned dx, unsigned dy,
  173.                       unsigned sx, unsigned sy,
  174.                       unsigned sdx, unsigned sdy, int direction)
  175. {
  176.    char *src;
  177.    char *dest;
  178.    int  tempdx;
  179.  
  180.    dest=(char *)normalize(d + dy*dw + dx);
  181.    VESAsetpage(VESAwhat_page(sy, sx));
  182.    src=(char *)normalize(_screen_start + VESAwhat_offset(sy,sx));
  183.    if (vgadebug) {
  184.       fprintf(vgadebug,"\nVESAcapt256(d=%Fp, dw=%u, %u, dx=%u, %u, sx=%u, %u,"
  185.                        "  sdx=%u, sdy=%u, direction=%u)\n",
  186.                        d, dw, dl, dx,dy,sx,sy,sdx,sdy,direction);
  187.    }
  188.    while (sdy) {
  189.        while ((Vnext_break_row != sy)&&(sdy>0)) {
  190.           memcpy(dest, src, sdx);
  191.           sy++; sdy--;
  192.           src=(char *)normalize(src+_screen_width);
  193.           dest=(char *)normalize(dest+dw);
  194.        }
  195.        if ( (sdy>0) && (Vnext_break_row == sy)) {
  196.      tempdx=Vnext_break_col - sx; /* number of bytes on this page */
  197.      if ( tempdx < 1 ) {  /* if no bytes on this page */
  198.         VESAsetpage(vesapage+1);
  199.         src=(char *)normalize
  200.             (_screen_start + VESAwhat_offset(sy,sx) );
  201.             memcpy(dest, src, sdx);
  202.             sy++; sdy--;
  203.             src=(char *)normalize(src+_screen_width);
  204.             if (sdy) dest=(char *)normalize(dest + dw);
  205.             continue;
  206.          }
  207.          if ( sdx > tempdx ) { /* split page */
  208.             memcpy(dest, src, tempdx);
  209.             VESAsetpage(vesapage+1);
  210.             src=(char *)normalize
  211.             (_screen_start + VESAwhat_offset(sy,sx+tempdx) );
  212.             memcpy((dest+tempdx), src, (sdx-tempdx));
  213.          } else { /* all on this page */
  214.             memcpy(dest, src, sdx);
  215.             VESAsetpage(vesapage+1);
  216.          }
  217.          sy++; sdy--;
  218.      src=(char *)normalize(_screen_start + VESAwhat_offset(sy,sx));
  219.        }
  220.        if (sdy) dest=(char *)normalize(dest + dw);
  221.    }
  222.    return(1);
  223. }
  224.